<template>
  <div>
    <el-form :model="form" label-width="120px">
      <el-form-item label="邮箱">
        <el-input v-model="form.email" />
      </el-form-item>
      <el-form-item label="密码">
        <el-input v-model="form.password" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">登录</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script setup>
import { ref } from "vue";
import { useRouter } from "vue-router";
import api from "../api/index";
const { push } = useRouter();
const form = ref({
  email: "",
  password: "",
});
const onSubmit = () => {
  api.post("/login", form.value).then((res) => {
    localStorage.setItem("token", res.data.token);
    push("/");
  });
};
</script>